import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 
 * @author karcio
 * 
 */
public class DB2Connect {
	public static void main(String[] args) {
		Connection connection = null;
		ResultSet resultSet = null;
		ResultSet resultSetOneValue = null;
		Statement statement = null;

		try {
			Class.forName("com.ibm.db2.jcc.DB2Driver");
			connection = DriverManager.getConnection(
					"jdbc:db2://localhost:50000/sample", "db2inst1", "sklejka");
			statement = connection.createStatement();
			resultSet = statement.executeQuery("SELECT FIRSTNME FROM EMP");

			while (resultSet.next()) {
				System.out.println("Employee name\t "
						+ resultSet.getString("FIRSTNME"));
			}

			resultSetOneValue = statement
					.executeQuery("SELECT FIRSTNME FROM EMP WHERE EMPNO=000070");
			while (resultSetOneValue.next()) {
				System.out.println("\nOnly one Employee name from list\t "
						+ resultSetOneValue.getString("FIRSTNME"));

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				resultSet.close();
				statement.close();
				connection.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
